/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.puzzud.engine.core;

/**
 *
 * @author puzzud
 */
public class Timer
{
    protected int value;
    protected int delay;

    public Timer()
    {
        set( 0 );
    }

    public Timer( int delay )
    {
        set( delay );
    }

    public int getDelay()
    {
        return( delay );
    }

    public void setDelay( int delay )
    {
        this.delay = delay;
    }

    public int getValue()
    {
        return( value );
    }

    public void setValue( int value )
    {
        this.value = value;
    }

    public void set( int value )
    {
        setDelay( value );
        setValue( value );
    }

    public void reset()
    {
        setValue( delay );
    }

    public boolean run()
    {
        value--;

        if( value == 0 )
        {
            return( true );
        }
        else
        {
            if( value < 0 )
            {
                reset();
            }
            
            return( false );
        }
    }
}